package edu.zjut.hjg.saas.kwmp.web.controller.home;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import edu.zjut.hjg.saas.biz.model.Kindergarten;
import edu.zjut.hjg.saas.biz.service.ActivityService;
import edu.zjut.hjg.saas.biz.service.BulletinService;
import edu.zjut.hjg.saas.biz.service.NewsService;
import edu.zjut.hjg.saas.common.annotation.RequestAttribute;

@Controller
@RequestMapping("/")
public class IndexController {

    @Autowired
    private BulletinService bulletinService;

    @Autowired
    private NewsService     newsService;

    @Autowired
    private ActivityService activityService;

    @RequestMapping("index.htm")
    public void index(@RequestAttribute Kindergarten app, Model model) {
        Integer appId = app.getId();
        model.addAttribute("bulletin", bulletinService.findByAppId(appId));
        model.addAttribute("activities", activityService.listByLimitAndAppId(8, appId));
        model.addAttribute("newses", newsService.listByAppId(appId, 8, 1).getValues());
    }
}
